package com.fy.shop.service;


import com.fy.common.util.BeansUtil;
import com.fy.shop.api.DistributorService;
import com.fy.shop.dto.*;
import com.fy.shop.entity.*;
import com.fy.shop.mapper.DistributorMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/show")
public class DistributorServiceImpl implements DistributorService {


    @Resource
    private DistributorMapper distributorMapper;

    @Override
    @GetMapping(value = "/recordFindAll")
    public List<RecordDto> recordFindAll(RecordDto recordDto) {
        RecordEntity recordEntity = new RecordEntity();
        BeanUtils.copyProperties(recordDto,recordEntity);
        List<RecordEntity> recordEntityList = distributorMapper.recordFindAll(recordEntity);
        List<RecordDto> recordDtos = BeansUtil.listCopy(recordEntityList,RecordDto.class);
        return recordDtos;
    }

    @Override
    @GetMapping(value = "/profitFindAll")
    public List<ProfitDto> profitFindAll(ProfitDto profitDto) {
        ProfitEntity profitEntity = new ProfitEntity();
        BeanUtils.copyProperties(profitDto,profitEntity);
        List<ProfitEntity> profitEntityList = distributorMapper.profitFindAll(profitEntity);
        List<ProfitDto> profitDtos = BeansUtil.listCopy(profitEntityList, ProfitDto.class);
        return profitDtos;
    }
    @Override
    @PostMapping(value = "/editPersonal")
    public int editPersonal(PersonalInformationDto personalInformationDto) {
        PersonalInformationEntity personalInformationEntity = new PersonalInformationEntity();
        BeanUtils.copyProperties(personalInformationDto,personalInformationEntity);
        return distributorMapper.editPersonal(personalInformationEntity);
    }

    @Override
    @PostMapping(value = "/editEnterprise")
    public int editEnterprise(EnterpriseInformationDto enterpriseInformationDto) {
        EnterpriseInformationEntity enterpriseInformationEntity = new EnterpriseInformationEntity();
        BeanUtils.copyProperties(enterpriseInformationDto,enterpriseInformationEntity);
        return distributorMapper.editEnterprise(enterpriseInformationEntity);
    }
    @Override
    @PostMapping(value ="/addProduct")
    public List<UpPlatformDto> addProduct(IsShowProductDto isShowProductDto) {
        IsShowProductEntity isShowProductEntity = new IsShowProductEntity();
        BeanUtils.copyProperties(isShowProductDto,isShowProductEntity);
        List<UpPlatformEntity> upPlatformEntityList = distributorMapper.addProduct(isShowProductEntity);
        return BeansUtil.listCopy(upPlatformEntityList,UpPlatformDto.class);
    }

    @Override
    @PostMapping(value ="/addProduct")
    public List<UpPlatformDto> removeProduct(IsShowProductDto isShowProductDto) {
        IsShowProductEntity isShowProductEntity = new IsShowProductEntity();
        BeanUtils.copyProperties(isShowProductDto,isShowProductEntity);
        List<UpPlatformEntity> upPlatformEntityList = distributorMapper.removeProduct(isShowProductEntity);
        return BeansUtil.listCopy(upPlatformEntityList,UpPlatformDto.class);
    }

    @Override
    @PostMapping(value ="/isShowProduct")
    public int isShowProduct(IsShowProductDto isShowProductDto) {
        IsShowProductEntity isShowProductEntity = new IsShowProductEntity();
        BeanUtils.copyProperties(isShowProductDto,isShowProductEntity);
        return distributorMapper.isShowProduct(isShowProductEntity);
    }

    @Override
    @PostMapping(value = "/updateEnter")
    public int updateEnter(SettledInputDto settledInputDto) {
        SettledInputEntity settledInputEntity = new SettledInputEntity();
        BeanUtils.copyProperties(settledInputDto,settledInputEntity);
        return distributorMapper.updateEnter(settledInputEntity);
    }

}
